#include <iostream>
#include <Windows.h>
#include <locale>
#include "User.h"
#include "DataManager.h"
#include "MenuShow.h" 

using namespace std;

int test();

int main()
{
    MenuShow computerAccessoriesInventoryManagementSystem;
    computerAccessoriesInventoryManagementSystem.menu_main();
    
    return 0;
}

int test()
{
    UserManager tmpManager;
    int chose;
    User tmpUser;
    MYPTR_T tmpPtr;

    int id,fid;
    string name;
    string password;
    PB_t permissionBits;
    int roleshow;
    Role role;
    string roleDescription;
    
    tmpManager.load_UserFromFile();

    while (1)
    {
        system("cls");
        cout << "1.增" << endl;
        cout << "2.删" << endl;
        cout << "3.改" << endl;
        cout << "4.查" << endl;
        cout << "5.显示所有用户" << endl;
        cout << "6.保存用户信息到文件" << endl;
        cout << "0.退出" << endl;
        cin >> chose;

        switch (chose)
        {
        case 1:
        {
            cout << "请输入用户id：";
            cin >> id;
            cout << "请输入用户名：";
            cin >> name;
            cout << "请输入用户密码：";
            cin >> password;
            cout << "请输入用户权限：";
            cin >> permissionBits;
            cout << "请输入用户角色：(1管理员、2配件信息人员、3仓库盘点人员、4仓库出入库管理人员)";
            cin >> roleshow;
            cout << "请输入用户描述：";
            cin >> roleDescription;
            tmpUser = User(id, name, password, permissionBits, roleDescription);
            switch (roleshow)
            {
                case 1:role = Role::ADMIN;break;
                case 2:role = Role::USER_INFO;break;
                case 3:role = Role::USER_STORE_CHECK;break;
                case  4:role = Role::USER_STORE_IO;break;
            }
            tmpManager.add_info(tmpUser,role);
            break; 
        }
            
        case 2:
        {
            cout << "请输入要删除的用户id：";
            cin >> id;
            tmpManager.delete_info(id);
            break;
        }
            
        case 3:
            cout << "请输入要修改的用户id：";
            cin >> fid;
            cout << "请输入新的用户id：";
            cin >> id;
            cout << "请输入新用户名：";
            cin >> name;
            cout << "请输入用户新密码：";
            cin >> password;
            cout << "请输入用户新权限：";
            cin >> permissionBits;
            cout << "请输入用户新描述：";
            cin >> roleDescription;
            tmpUser = User(id, name, password, permissionBits, roleDescription);
            tmpManager.modify_info(fid, tmpUser);
            break;
        case 4:
            cout << "请输入要查找的用户id：";
            cin >> id;
            if ((tmpPtr = tmpManager.find_info(id)) == nullptr)
            {
                cout << "用户不存在！" << endl;
            }
            else
            {
                cout << tmpPtr->serialize();
            }
            break;
        case 5:
            tmpManager.show_UserInfo();
            break;
        case 6:
            tmpManager.save_UserToFile();
            break;
        case 0:return 0;
        }
        system("pause");
    }
}
